<?php

namespace App\Repository\Msq;

use App\Model\User\UserModel;
use App\Repository\RepositoryGeneral;
use Hyperf\Di\Annotation\Inject;

class UserMsq extends RepositoryGeneral
{
    #[Inject]
    public UserModel $userModel;

    public function getUserInfoByAccount(string $account,array $select = ["*"]){
        return $this->userModel
            ->select($select)
            ->withCustomCondition()
            ->where('user_account',$account)
            ->first()
            ->toArray();
    }

    public function getUserInfo(string $userId,array $select = ["*"]){
        return $this->userModel
            ->withCustomCondition()
            ->select($select)
            ->first($userId)
            ->toArray();
    }

    public function userExists($data){
        return $this->userModel
            ->withCustomCondition()
            ->where(function($query) use ($data) {
                $query->orWhere('user_account', $data['user_account'])
                    ->orWhere('user_phone', $data['user_phone'])
                    ->orWhere('user_email', $data['user_email']);
            })
            ->first();
    }

    public function addUser(array $data){
        return $this->userModel->create($data);
    }


}